<template>
  <div>
    <hr class="two" />
    <h1>AgentServer 使用 Axios 解决跨域问题</h1>
    <button @click="getStudents">获取学生信息</button>
    <button @click="getCars">获取汽车信息</button>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  name: 'App',
  methods: {
    getStudents() {
      axios.get('https://www.baidu.com').then(
          response => {
            console.log('请求成功了', response.data)
          },
          error => {
            console.log('请求失败了', error.message)
          }
      )
    },

    /*首先访问本地服务器的资源，不走代理
    * */
    getCars() {
      axios.get('http://localhost:8081/test.txt').then(
          response => {
            console.log('请求成功了', response.data)
          },
          error => {
            console.log('请求失败了', error.message)
          }
      )
    }
  },
}
</script>
